package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAO.DishDAO;
import DTO.DishDTO;

/**
 * Servlet implementation class DishClientServlet
 */
public class DishClientServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DishClientServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if (null == request.getParameter("id")) {
			RequestDispatcher rd = request.getRequestDispatcher("dish-details.jsp");
			rd.forward(request, response);
		} else {
			int dishId = Integer.parseInt(request.getParameter("dishId"));
			DishDAO dishDAO = new DishDAO();
			DishDTO dishDTO = new DishDTO();
			dishDTO.setId(dishId);
			dishDAO.get(dishDTO);
			request.setAttribute("DISHDTO", dishDTO);
			RequestDispatcher rd = request.getRequestDispatcher("dish-details.jsp");
			rd.forward(request, response);
		}
	}

}
